//
//  CategoryViewController.m
//  groupProject
//
//  Created by mac on 15/12/17.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CategoryViewController.h"
#import "Config.h"
@interface CategoryViewController ()

@end

@implementation CategoryViewController{
    NSMutableArray * data1;
    NSMutableArray * data2;
}
@synthesize FirstCategory,SecondCategory;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    FirstCategory  =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH/3.0, SCREEN_HEIGHT-49)];
    
    FirstCategory.dataSource =self;
    FirstCategory.delegate = self;
    SecondCategory = [[UITableView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/3.0, 64, SCREEN_WIDTH/3.0 *2, SCREEN_HEIGHT-49-64)];
    SecondCategory.dataSource =self;
    SecondCategory.delegate = self;
    [self.view addSubview:FirstCategory];
    [self.view addSubview:SecondCategory];
    data1 = [NSMutableArray arrayWithObjects:@"Marvel Superhero",@"Necklace1",@"Watch",@"RockiSirT-shirt", nil];
    data2 = [NSMutableArray array];
    for (int i = 0; i<40; i++) {
        NSString * str1 = [NSString stringWithFormat:@"食品%d",i];
        [data2 addObject:str1];
        
    }
    
    
    
}
#pragma mark -   显示行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == FirstCategory) {
        return data1.count;
    }
    if (tableView == SecondCategory) {
        return data2.count;
    }
    
    return 0;
    
}
#pragma mark - 显示数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableArray * tmpArray = [[NSMutableArray alloc]init];
    if (tableView == FirstCategory) {
        tmpArray = data1;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
        }
        cell.textLabel.text = [tmpArray objectAtIndex:indexPath.row];
        return cell;
    }else if(tableView == SecondCategory){
        tmpArray = data2;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
        }
        cell.textLabel.text = [tmpArray objectAtIndex:indexPath.row];
        return cell;
    }
    return nil;
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == FirstCategory) {
        if (indexPath.row==0) {
            [SecondCategory  scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
        } else if(indexPath.row == 1) {
            [SecondCategory  scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:11 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
        } else {
            [SecondCategory  scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:23 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }
        //- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
    }
    if (tableView == SecondCategory) {
        if (indexPath.row >= 0 && indexPath.row <= 11) {
            [FirstCategory selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
            //- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
        } else if (indexPath.row <= 23) {
            [FirstCategory selectRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
        } else {
            [FirstCategory selectRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
